﻿using ParkSaleForAdmin.Data;
using ParkSaleForAdmin.Foundation;
using System.Windows;

namespace ParkSaleForAdmin.FunctionWindow
{
    public class CompanyInfo
    {
        [DataToUI("ID", "id", false)]
        public string ID
        {
            get;
            set;
        }
        [DataToUI("企业名称", "name")]
        public string Name
        {
            get; set;
        }
        [DataToUI("企业信息", "about")]
        public string About
        {
            get;
            set;
        }
        [DataToUI("联系电话", "phone")]
        public string Phone
        {
            get;
            set;
        }
        [DataToUI("电子邮件", "email")]
        public string Email
        {
            get;
            set;
        }
        [DataToUI("企业类型 1开发商 2承包商 0其他", "type")]
        public string Type
        {
            get;
            set;
        }
        public CompanyInfo()
        {

        }
        public CompanyInfo(DatabaseData data)
        {

        }

        //public CompanyInfo Parse(DatabaseData data)
        //{
        //    ID = int.Parse(data["id"].Value);
        //    Name = data["name"].Value;
        //    About = data["about"].Value;
        //    Phone = data["phone"].Value;
        //    Email = data["email"].Value;
        //    Type = data["type"].Value;
        //    return this;
        //}
    }

    /// <summary>
    /// CompanyManagement.xaml 的交互逻辑
    /// </summary>
    public class CompanyManagement : BasicManagerWindow<CompanyInfo>
    {

        public override string TableName => "Company";


        //   protected override string[] values => new string[] { "id", "name", "about", "phone", "email", "type" };

        // protected override string[] titles => new string[] { "ID", "企业名", "企业介绍", "联系电话", "电子邮件", "企业类型 1开发商 2承包商 0其他" };

        // protected override string[] BindingName => new string[] { "ID", "Name", "About", "Phone", "Email", "Type" };

        //protected override string[] InputBoxTitle => new string[] { "企业名", "企业介绍", "联系电话", "电子邮件", "企业类型 1开发商 2承包商 0其他" };

        //protected override string[] InputBoxValue => new string[] { "name", "about", "phone", "email", "type" };

        public CompanyManagement()
        {

            Title = "企业管理";
        }

        protected override bool EachArgForAppend(string n, string value)
        {

            if (n.Equals("type"))
            {
                try
                {
                    int t = int.Parse(value);
                    if (t >= 0 && t <= 2)
                    {
                        return true;
                    }
                    else
                    {
                        MessageBox.Show("输入范围错误", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                        return false;
                    }
                }
                catch
                {
                    MessageBox.Show("类型输入错误", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                    return false;
                }
            }
            else
            {
                return true;
            }
        }

        public override string DeleteStr(CompanyInfo obj)
        {
            return SQLHelpler.MakeSelectStr(TableName, "id", obj.ID);
        }

        public override string AppendStr(CompanyInfo obj)
        {
            return SQLHelpler.MakeSelectStr(TableName, "id", 9999999999.ToString());
        }

        public override string ChangeStr(CompanyInfo obj)
        {
            return SQLHelpler.MakeSelectStr(TableName, "id", obj.ID);
        }



    }
}
